package com.taiyuan.tongcheng.ui;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import net.sourceforge.simcpux.Constants;
import net.sourceforge.simcpux.MD5;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpConfig;
import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.BindView;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.StringUtils;
import org.kymjs.kjframe.utils.SystemTool;

import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.taiyuan.tongcheng.adapter.CarKindAdapter;
import com.taiyuan.tongcheng.adapter.OderStationAdapter;
import com.taiyuan.tongcheng.adapter.OrderCancelAdapter;
import com.taiyuan.tongcheng.adapter.PayKindAdapter;
import com.taiyuan.tongcheng.application.TCBroadcastAction;
import com.taiyuan.tongcheng.bean.BjExtraServiceInfo;
import com.taiyuan.tongcheng.bean.BjOrderInfo;
import com.taiyuan.tongcheng.bean.ExtraServiceInfo;
import com.taiyuan.tongcheng.bean.ZcOrderInfo;
import com.taiyuan.tongcheng.config.TcConfig;
import com.taiyuan.tongcheng.http.HttpParamUtil;
import com.taiyuan.tongcheng.http.TcWebservice;
import com.taiyuan.tongcheng.http.WebData;
import com.taiyuan.tongcheng.jsonparser.TcJsParser;
import com.taiyuan.tongcheng.pay.WxPay;
import com.taiyuan.tongcheng.ui.fragment.OrderMovingFragment;
import com.taiyuan.tongcheng.util.ACache;
import com.taiyuan.tongcheng.util.TcUtil;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tytc56.user.R;

/**
 * 
* @Description 搬家订单界面
* @author wzq
* @date 2015-9-18 上午10:02:02
* @update (date)
* @version V1.0
 */
public class MovingOrderDetailActivity extends BaseActivity{
	//==widget
	@BindView(id=R.id.btn_make_order,click=true)
	private Button  orderBtn;
	//基本信息
	@BindView(id=R.id.tv_order_state)
	private TextView orderStateTv;
	@BindView(id=R.id.tv_moving_start)
	private TextView  startTv;
	@BindView(id=R.id.tv_moving_end)
	private TextView  endTv;
	@BindView(id=R.id.tv_moving_time)
	private TextView  timeTv;
	@BindView(id=R.id.tv_moving_pay_style)
	private TextView  payTv;
	@BindView(id=R.id.tv_moving_note)
	private TextView  noteTv;
	@BindView(id=R.id.tv_moving_car_style)
	private TextView  carStyle;
	@BindView(id=R.id.tv_moving_tel)
	private TextView  telTv;
	// 评价
	@BindView(id = R.id.ll_order_mark)
	private LinearLayout markLinearLayout;
	@BindView(id = R.id.rataingBar)
	private RatingBar rationgBar;
	@BindView(id=R.id.tv_mark_time)
	private TextView  markTime;
	
	//价格
	@BindView(id =R.id.tv_moving_all_price)
	private TextView movingAllPriceTv;
	@BindView(id =R.id.tv_allprice_lable)
	private TextView movingAllPriceLable;
	@BindView(id =R.id.tv_price_moving)
	private TextView movingOrderTv;
	@BindView(id =R.id.tv_price_moving_service)
	private TextView servicePriceTv;
	@BindView(id=R.id.tv_furniture_num)
	private TextView furnitureNumTv;
	@BindView(id=R.id.tv_air_num)
	private TextView airNumTv;
	@BindView(id=R.id.tv_valuables_num)
	private TextView valuesNumTv;
	@BindView(id=R.id.tv_meirong_num)
	private TextView meirongNumTv;

	//配送司机信息
	@BindView(id=R.id.ll_order_driver_msg)
	private LinearLayout  driverLayout ;
	@BindView(id=R.id.tv_order_driver_name)
	private TextView  driverName;
	@BindView(id=R.id.tv_order_car_no)
	private TextView  driverCarno;
	@BindView(id=R.id.btn_order_driver_call,click=true)
	private Button   driverTelBtn ;
	
	//价格详情
	@BindView(id=R.id.ll_btn_detail_extral,click=true)
	private LinearLayout  detailBtn;
	@BindView(id=R.id.img_detail_arrow)
	private ImageView arrowImg;
	@BindView(id=R.id.ll_moving_price_detail)
	private LinearLayout  priceDetailLayout;
	@BindView(id=R.id.tv_price_start)
	private TextView startPrice;
	@BindView(id=R.id.tv_price_km)
	private TextView kmPrice;
	@BindView(id=R.id.tv_price_czservice)
	private TextView servicePrice;
	@BindView(id=R.id.tv_price_night)
	private TextView nightPrice;
	@BindView(id=R.id.tv_price_floor)
	private TextView floorPrice;
	@BindView(id=R.id.tv_coupon)
    private TextView couponPrice;	

	//工具bar
	@BindView(id =R.id.tv_order_price)
	private TextView orderPrice;
	@BindView(id=R.id.btn_order_kind,click=true)
	private Button orderPayBtn;
	@BindView(id=R.id.btn_order_mark,click=true)
	private Button orderMarkBtn;
	@BindView(id=R.id.btn_order_cancel,click=true)
	private Button orderCancelBtn;
	@BindView(id=R.id.btn_order_cakan,click=true)
	private Button orderCakanBtn;
	@BindView(id=R.id.btn_order_moving_part_pay,click=true)
	private Button orderPartPay;
	@BindView(id=R.id.btn_order_moving_finish,click=true)
	private Button orderFinishBtn;
	@BindView(id=R.id.btn_order_modify_confirm,click=true)
	private Button orderConfirmBtn;
	@BindView(id=R.id.rl_bottom)
	private RelativeLayout   bottomRl;
	//==data
	private BjOrderInfo  movingOrder=new BjOrderInfo();
	private List<BjExtraServiceInfo> serviceList =new ArrayList<BjExtraServiceInfo>();
	private List<String> serviceListString =new ArrayList<String>();
	//跳转intent
	private Intent cancelIntent;
	private Intent markIntent;
	//微信
	private PayReq req;
	public  IWXAPI msgApi;
	
	//价格详情
	@BindView(id=R.id.rl_moving_serive_detail,click=true)//详情页打开
	private RelativeLayout movingServiceDetailRl;
	@BindView(id=R.id.img_service_price_detail,click=true)
	private ImageView rightArrowImg;
	@BindView(id=R.id.rl_moving_serive_close,click=true)//详情页关闭
	private RelativeLayout movingServiceCloseRL;
	@BindView(id=R.id.tv_service_price1)
	private TextView  priceServiceTv1;
	@BindView(id=R.id.tv_service_price2)
	private TextView  priceServiceTv2;
	@BindView(id=R.id.tv_service_price3)
	private TextView  priceServiceTv3;
	@BindView(id=R.id.tv_service_price4)
	private TextView  priceServiceTv4;
	@BindView(id=R.id.ll_service_price_detail)
	private LinearLayout  serviceDetailLayout;
	@BindView(id=R.id.top_ll)
	private ScrollView  contentScrollView;
	@BindView(id=R.id.rl_service_1)
	private RelativeLayout service1RL;
	@BindView(id=R.id.rl_service_2)
	private RelativeLayout service2RL;
	@BindView(id=R.id.rl_service_3)
	private RelativeLayout service3RL;
	@BindView(id=R.id.rl_service_4)
	private RelativeLayout service4RL;
	
    @Override
    public void setRootView() {
    	super.setRootView();
    	setContentView(R.layout.activity_movingodrer_detail);
    }
    
    @Override
    public void initWidget() {
    	super.initWidget();
    	initView();
    	cancelIntent=new Intent(this,OrderCancelActivity.class);
		markIntent=new Intent(this,MarkActivity.class);
    	//微信参数
		msgApi=WXAPIFactory.createWXAPI(this, null);
		req = new PayReq();
		msgApi.registerApp(Constants.APP_ID);
		
    	movingOrder=(BjOrderInfo)getIntent().getSerializableExtra(OrderMovingFragment.TAG_MOVING_ORDER);
    	KJLoger.debug("*====**"+movingOrder.toString());
    	initUiData(movingOrder);
    }
    
    @Override
    public void initData() {
    	super.initData();
  
    }
    
    
    @Override
    public void widgetClick(View v) {
    	super.widgetClick(v);
    	switch (v.getId()) {
		case R.id.btn_make_order:
			break;
		case R.id.ll_btn_detail_extral:
			if(priceDetailLayout.getVisibility()==View.GONE){
				priceDetailLayout.setVisibility(View.VISIBLE);
				arrowImg.setImageResource(R.drawable.icon_arrow_up);
			}else{
				priceDetailLayout.setVisibility(View.GONE);
				arrowImg.setImageResource(R.drawable.icon_arrow_down);
			}
			break;
		case R.id.btn_order_driver_call:
			Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+ movingOrder.getDriverMobile()));
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(intent);
			break;
		case R.id.btn_order_kind:
			sendBroadcast(new Intent(TCBroadcastAction.DIALOG_SHOW));
			payMoney(movingOrder.getBjOrderId(),0);
			break;
		case R.id.btn_order_cancel:
			cancelIntent.putExtra(TcConfig.IntentTag.Order_Id, movingOrder.getBjOrderId());
			cancelIntent.putExtra(OrderCancelActivity.TAG_CANCEL_KIND, OrderCancelAdapter.CANCEL_ADAPTER_MOVING);
			KJLoger.debug("订单ID"+movingOrder.getBjOrderId());
			KJLoger.debug("订单NO"+movingOrder.getBjOrderNo());
			KJLoger.debug("订单状态"+movingOrder.getStatus());
			startActivity(cancelIntent);
			break;
		case R.id.btn_order_mark:
			markIntent.putExtra(MarkActivity.TAG_MARK_ORDER_FROM, MarkActivity.ORDER_FROM_MOVING);
			markIntent.putExtra(MarkActivity.TAG_MARK_ORDER_ID, movingOrder.getBjOrderId());
		    startActivity(markIntent);
			break;
		case R.id.btn_order_modify_confirm:
			sendBroadcast(new Intent(TCBroadcastAction.DIALOG_SHOW));
			confirmOrderModify(movingOrder.getBjOrderId());
			break;
		case R.id.btn_order_moving_part_pay:
			sendBroadcast(new Intent(TCBroadcastAction.DIALOG_SHOW));
			payMoney(movingOrder.getBjOrderId(),1);
			break;
		case R.id.btn_order_moving_finish:
			sendBroadcast(new Intent(TCBroadcastAction.DIALOG_SHOW));
			confirmOrderFinish(movingOrder.getBjOrderId());
			break;
		case R.id.rl_moving_serive_detail:
			if(movingOrder.getExtraServicePrice()>0){
				serviceDetailLayout.setVisibility(View.VISIBLE);
				rightArrowImg.setVisibility(View.GONE);
//				handler.post(new Runnable() {
//				    @Override
//				    public void run() {
//				    	contentScrollView.fullScroll(ScrollView.FOCUS_DOWN);
//				    }
//				});
			}
			break;
		case R.id.rl_moving_serive_close:
			serviceDetailLayout.setVisibility(View.GONE);
			rightArrowImg.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}
    }
    
    
    /**
     * 
    * @Description: 判断输入条件
    * @return
    * @return boolean
    * @throws
    * @autour wzq
    * @date 2015-9-18 上午10:29:17
    * @update (date)
     */
    private boolean check() {
    	if(SystemTool.checkNet(getApplicationContext())){
    		return true;
    	}else{
    		return false;
    	}
	}
    
    /**
     * 
    * @Description: 刷新界面数据
    * @param orderInfo
    * @return void
    * @throws
    * @autour wzq
    * @date 2015-9-22 下午3:29:27
    * @update (date)
     */
    private void initUiData(BjOrderInfo orderInfo) {
    	
    	//司机信息
		if(orderInfo.getStatus()==TcConfig.OrderStatus.PRE_RESPONSE||orderInfo.getStatus()==TcConfig.OrderStatus.CANCEL){
			driverLayout.setVisibility(View.GONE);
		}else{
			driverLayout.setVisibility(View.VISIBLE);
			driverName.setText(orderInfo.getDriverName());
			driverCarno.setText(orderInfo.getTruckNumber());
		}
    	topTv.setText(R.string.top_title_detail);
    	rightTv.setVisibility(View.GONE);
    	//价格
    	movingAllPriceLable.setText("订单总价");
    	KJLoger.debug(orderInfo.getExtraServiceInfo());
    	if(!StringUtils.isEmpty(orderInfo.getExtraServiceInfo())&&orderInfo.getExtraServiceInfo().length()>3){
    		serviceListString=JSON.parseArray(orderInfo.getExtraServiceInfo(), String.class);
        	for (String serviceString: serviceListString) {
    			BjExtraServiceInfo  serviceInfo =JSON.parseObject(serviceString, BjExtraServiceInfo.class);
//    			KJLoger.debug(serviceInfo.toString());
    			switch (serviceInfo.getBjExtraServiceId()) {
    			case MovingListActivity.FURNITURE_KIND:
    				furnitureNumTv.setText("X"+serviceInfo.getNum());
    				service1RL.setVisibility(View.VISIBLE);
    				priceServiceTv1.setText(getServicePriceDetailString(serviceInfo));
    				break;
    			case MovingListActivity.KONGTIAO_KIND:
    				airNumTv.setText("X"+serviceInfo.getNum());
    				service2RL.setVisibility(View.VISIBLE);
    				priceServiceTv2.setText(getServicePriceDetailString(serviceInfo));
    				break;
    			case MovingListActivity.PRECIOUS_KIND:
    				valuesNumTv.setText("X"+serviceInfo.getNum());
    				service3RL.setVisibility(View.VISIBLE);
    				priceServiceTv3.setText(getServicePriceDetailString(serviceInfo));
    				break;
    			case MovingListActivity.MEIRONG_KIND:
    				meirongNumTv.setText("X"+serviceInfo.getNum());
    				service4RL.setVisibility(View.VISIBLE);
    				priceServiceTv4.setText(getServicePriceDetailString(serviceInfo));
    				break;
    			default:
    				break;
    			}
        	}
    	}
    	
    	if(orderInfo.getExtraServicePrice()>0){
    		
    	}else{
    		rightArrowImg.setVisibility(View.GONE);
    	}
    	movingAllPriceTv.setText("￥"+orderInfo.getActualOrderMoney());
    	movingOrderTv.setText(orderInfo.getLiChengPrice()+"");
    	servicePriceTv.setText(orderInfo.getLiChengPrice()+"");
    	serviceList=orderInfo.getExtraServiceInfoList();
    	
    	//价格详情
    	startPrice.setText("￥"+orderInfo.getStartPrice());
    	kmPrice.setText("￥"+orderInfo.getLiChengPrice());
    	nightPrice.setText("￥"+orderInfo.getNightServicePrice());
    	floorPrice.setText("￥"+orderInfo.getTotalFloorPrice());
    	servicePrice.setText("￥"+orderInfo.getExtraServicePrice());
    	couponPrice.setText("￥-"+orderInfo.getMoneyCardValue());
    	
    	//基本信息
    	startTv.setText(orderInfo.getStartPlace());
    	endTv.setText(orderInfo.getEndPlace());
    	timeTv.setText(orderInfo.getServiceDate());
    	payTv.setText(PayKindAdapter.payName[orderInfo.getPayTypeId()-1]);
    	carStyle.setText(CarKindAdapter.carName[orderInfo.getTruckTypeId()-1]);
    	telTv.setText(orderInfo.getReceiverMobile());
    	if(StringUtils.isEmpty(orderInfo.getNote())){
    		noteTv.setText("无");
    	}else{
    		noteTv.setText(orderInfo.getNote());
    	}
    	// 评价信息
		rationgBar.setIsIndicator(true);
		if (orderInfo.getIsCommentFlag()== 1) {
			markLinearLayout.setVisibility(View.VISIBLE);
			rationgBar.setRating(Float.parseFloat(orderInfo.getCommentScore()));
			markTime.setText("评价时间:"+orderInfo.getCommentTime());
		} else {
			markLinearLayout.setVisibility(View.GONE);
		}
    	initOrderBarUi(orderInfo);
	}
	/**
	 * huoqu 价格
	 * @param serviceInfo
	 * @return
	 */
    private String  getServicePriceDetailString(BjExtraServiceInfo  serviceInfo) {
    	if(serviceInfo.getNum()>0){
    		return  serviceInfo.getName()+"："+serviceInfo.getNum()+"*"+serviceInfo.getPrice()+"(单价) ="+serviceInfo.getNum()*serviceInfo.getPrice();
    	}else{
    		return  serviceInfo.getName()+"："+serviceInfo.getNum()+"*"+serviceInfo.getPrice()+"(单价) = 0.0";
    	}
	}
    
	/**
	 * 
	 * @Description: 刷新订单bar
	 * @param orderInfo
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-14 下午7:18:36
	 * @update (date)
	 */
	private void initOrderBarUi(BjOrderInfo orderInfo) {
		orderPrice.setVisibility(View.GONE);
		
		switch (orderInfo.getStatus()) {
		case TcConfig.OrderStatus.PRE_RESPONSE://待响应状态 （取消，定金支付）
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_RES);
			orderCancelBtn.setVisibility(View.VISIBLE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderPayBtn.setVisibility(View.GONE);
		    
		    
		    if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_NULL){
		    	if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_PART){
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    	}else{
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
						orderPartPay.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    		orderPartPay.setVisibility(View.VISIBLE);
		    	}
		    }
			break;
		case TcConfig.OrderStatus.PRE_TAKEGOODS://待收货状态 （取消，修改确定（未确定））
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_CARRAY);
			orderPartPay.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.VISIBLE);
			orderPrice.setVisibility(View.VISIBLE);
			   
		    if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_NULL){
		    	if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_PART){
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    	}else{
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    		orderPartPay.setVisibility(View.VISIBLE);
		    	}
		    }
			break;
			
		case TcConfig.OrderStatus.PRE_CARRY://（取消，支付，修改确定（未确定））
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_CARRAY);
			orderCancelBtn.setVisibility(View.GONE);
			orderPartPay.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderPrice.setVisibility(View.VISIBLE);
			
			   
		    if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_NULL){
		    	if(TcUtil.getMovingPay(orderInfo)==TcUtil.OrderPayState.PAY_PART){
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    	}else{
		    		orderPayBtn.setVisibility(View.VISIBLE);
		    		if(orderInfo.getPayTypeId()!=1){
						orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
						orderPayBtn.setClickable(false);
					}
		    		orderPartPay.setVisibility(View.VISIBLE);
		    	}
		    }
			break;
		case TcConfig.OrderStatus.DELIVERING://配送中（支付（全款）   完成 ）
			orderStateTv.setText(TcConfig.OrderStatusLable.CARRAY_ING);
			orderCakanBtn.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			orderPartPay.setVisibility(View.GONE);
			orderFinishBtn.setVisibility(View.VISIBLE);
			orderPrice.setVisibility(View.VISIBLE);
			
			if (TcUtil.getMovingPay(orderInfo) != TcUtil.OrderPayState.PAY_ALL) {
				orderPayBtn.setVisibility(View.VISIBLE);
				if(orderInfo.getPayTypeId()!=1){
					orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
					orderPayBtn.setClickable(false);
				}
			} else {
				orderPayBtn.setVisibility(View.GONE);
			}
			
			break;
		case TcConfig.OrderStatus.FINISH:
			orderStateTv.setText(TcConfig.OrderStatusLable.FINISH);
			if(orderInfo.getIsCommentFlag()==0){
				orderMarkBtn.setVisibility(View.VISIBLE);
			}else{
				orderMarkBtn.setVisibility(View.GONE);
			}
			orderFinishBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			orderPrice.setVisibility(View.GONE);
			orderPayBtn.setVisibility(View.GONE);
			orderPartPay.setVisibility(View.GONE);
			break;
		case TcConfig.OrderStatus.CANCEL:
			orderStateTv.setText("已取消");
			orderPrice.setVisibility(View.GONE);
			orderPayBtn.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			orderPartPay.setVisibility(View.GONE);
        	orderFinishBtn.setVisibility(View.GONE);
			break;
		default:
			break;
		}
		
		orderCakanBtn.setVisibility(View.GONE);
		if(orderInfo.getIsUserConfirmFlag().equals("0")){
			orderConfirmBtn.setVisibility(View.VISIBLE);
			orderPartPay.setVisibility(View.GONE);
		}else{
			orderConfirmBtn.setVisibility(View.GONE);
		}
		
	}
	
	/**
	 * 
	* @Description: 订单确定修改
	* @param orderId
	* @return void
	* @autour wzq
	* @date 2015-9-21 下午4:32:52
	* @update (date)
	 */
	private void confirmOrderModify(String orderId) {

		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjHttp = new KJHttp(config);
        HttpParams params =new HttpParams();
        params=HttpParamUtil.getMovingOrderModify(this, orderId);
        kjHttp.post(TcWebservice.WEBSERVER_IP+TcWebservice.API.MOVING_ORDER_CONFIRM, params, new HttpCallBack() {
			@Override
			public void onFailure(int errorNo, String strMsg) {
				super.onFailure(errorNo, strMsg);
			}
			@Override
			public void onSuccess(String t) {
				try {
					String date=URLDecoder.decode(t, "UTF-8");
					KJLoger.debug(date);
					WebData webdata = TcJsParser.getWedataData(date); 
					if(webdata.getStatus()==1){
						refreashBjOrderInfo(movingOrder);
					}else{
						showErroCustomToast(webdata.getMsg());
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				super.onSuccess(t);
			}
        });
	
	}
	
	
	/**
	 * 
	* @Description: 订单确定修改
	* @param orderId
	* @return void
	* @autour wzq
	* @date 2015-9-21 下午4:32:52
	* @update (date)
	 */
	private void confirmOrderFinish(String orderId) {

		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjHttp = new KJHttp(config);
        HttpParams params =new HttpParams();
        params=HttpParamUtil.getMovingOrderComplish(getApplicationContext(), orderId);
        kjHttp.post(TcWebservice.WEBSERVER_IP+TcWebservice.API.MOVING_ORDER_FINISH, params, new HttpCallBack() {
			@Override
			public void onFailure(int errorNo, String strMsg) {
				super.onFailure(errorNo, strMsg);
			}
			@Override
			public void onSuccess(String t) {
				try {
					String date=URLDecoder.decode(t, "UTF-8");
					KJLoger.debug(date);
					WebData webdata = TcJsParser.getWedataData(date); 
					if(webdata.getStatus()==1){
						refreashBjOrderInfo(movingOrder);
					}else{
						showErroCustomToast(webdata.getMsg());
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				super.onSuccess(t);
			}
        });
	
	}
	
	
	
/**
 * 
* @Description: 掉起微信支付
* @param orderId
* djFlag 是否是支付定金，1为是，0和空为不是
* @return void
* @throws
* @autour wzq
* @date 2015-9-14 下午7:10:25
* @update (date)
 */
	private void payMoney(String orderId,int djFlag) {
		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjh = new KJHttp(config);
		HttpParams params = new HttpParams();
        params= HttpParamUtil.getMovingWxPay(this, orderId, djFlag);
        KJLoger.debug(params.getUrlParams().toString());
        kjh.post(TcWebservice.WEBSERVER_IP+TcWebservice.API.MOVING_ORDER_WXPAY, params, new HttpCallBack() {

			@Override
			public void onSuccess(String t) {
				super.onSuccess(t);
				String str;
				try {
					str = URLDecoder.decode(new String(t), "UTF-8");
					KJLoger.debug(str);
					WebData webData = TcJsParser.getWedataData(str);
					if (webData.getStatus() == 1) {
						WxPay payParam =JSON.parseObject(webData.getData(), WxPay.class);
						initWxPay(payParam);
					} else {
						
					}
					
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
			}
			
			
			@Override
    		public void onFailure(int errorNo, String strMsg) {
    			super.onFailure(errorNo, strMsg);
    		}
    		
    		@Override
    		public void onFinish() {
    			super.onFinish();
    		}
        });
	}
	
	/**
	 * 
	* @Description: 获取验证密钥
	* @param params
	* @return
	* @return String
	* @throws
	* @autour wzq
	* @date 2015-9-14 上午8:23:03
	* @update (date)
	 */
	private String genAppSign(List<NameValuePair> params) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < params.size(); i++) {
			sb.append(params.get(i).getName());
			sb.append('=');
			sb.append(params.get(i).getValue());
			sb.append('&');
		}
		sb.append("key=");
		sb.append(Constants.API_KEY);
		String appSign = MD5.getMessageDigest(sb.toString().getBytes()).toUpperCase();
		Log.e("orion",appSign);
		return appSign;
	}
	
	private void initWxPay(WxPay payParam) {
		req.appId = Constants.APP_ID;
		req.partnerId = Constants.MCH_ID;
		req.prepayId = payParam.getPrepayid();
		req.packageValue = "Sign=WXPay";
		req.nonceStr = payParam.getRad();
		req.timeStamp =System.currentTimeMillis()/1000+"";
		
		List<NameValuePair> signParams = new LinkedList<NameValuePair>();
		signParams.add(new BasicNameValuePair("appid", req.appId));
		signParams.add(new BasicNameValuePair("noncestr", req.nonceStr));
		signParams.add(new BasicNameValuePair("package", req.packageValue));
		signParams.add(new BasicNameValuePair("partnerid", req.partnerId));
		signParams.add(new BasicNameValuePair("prepayid", req.prepayId));
		signParams.add(new BasicNameValuePair("timestamp", req.timeStamp));
//		req.sign = payParam.getSign();
		req.sign = genAppSign(signParams);
		msgApi.registerApp(Constants.APP_ID);
		msgApi.sendReq(req);
	}
	
	/**
	 * 
	* @Description: 刷新页面数据
	* @param bjInfo
	* @return void
	* @throws
	* @autour wzq
	* @date 2015-9-22 下午6:12:08
	* @update (date)
	 */
	private void refreashBjOrderInfo(BjOrderInfo  bjInfo) {

		TcLoaddingDialog.show();
		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjHttp = new KJHttp(config);
		HttpParams params = new HttpParams();
		params = HttpParamUtil.getMovingOrderInfo(getApplicationContext(),
				bjInfo.getBjOrderId());
		kjHttp.post(TcWebservice.WEBSERVER_IP
				+ TcWebservice.API.MOVING_ORDER_DETAIL, params,
				new HttpCallBack() {
					@Override
					public void onFailure(int errorNo, String strMsg) {
						super.onFailure(errorNo, strMsg);
					}

					@Override
					public void onSuccess(String t) {
						try {
							String date = URLDecoder.decode(t, "UTF-8");
							KJLoger.debug(date);
							WebData webdata = TcJsParser.getWedataData(date);
							if (webdata.getStatus() == 1) {
								BjOrderInfo newOrderInfo = JSON.parseObject(
										webdata.getData(), BjOrderInfo.class);
								initUiData(newOrderInfo);
							}else if(webdata.getStatus()==-1){
								showErroCustomToast(webdata.getMsg());
								GotoLogin();
							} else {
								showErroCustomToast(webdata.getMsg());
							}
							if (TcLoaddingDialog.isShowing()) {
								TcLoaddingDialog.cancel();
							}
						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
						super.onSuccess(t);
					}
				});
	}
    
}
